export function pickFormRequired<T extends Record<string, any>> (formRules: { [key: string]: Array<any> }): T {
  return Object.entries(formRules).reduce((base, [k, value]) => {
    const isRequired = value.some(({ required }) => required)
    if (isRequired) {
      (base as any)[k] = ''
    }
    return base
  }, {} as T)
}

export function isEmptyObject (obj: Record<string, any>) {
  return Object.entries(obj).length === 0
}

export function throttle () {
  let timer: any
  return (fn: (...args: any) => unknown, delay: number) => {
    clearTimeout(timer)
    timer = setTimeout(() => {
      fn()
    }, delay)
  }
}
